<?php

namespace App\Models\User;

use App\Models\Common\CommonModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends CommonModel
{
    use HasFactory,SoftDeletes;
    protected $table = 'user';

    public $guardUserId;
    public $reason;


    public function addPoint($score,$reason='后台加分') {
        $this->point += $score;
        $this->save();
        PointLog::query()->create(['user_id'=>$this->id,
            'name'=>$this->name,
            'phone'=>$this->phone,
            'passport'=>$this->passport,
            'action'=>'add','point'=>$score,
            'reason'=>$reason]);
    }
    public function diviPoint($score,$reason='兑换商品') {
        $this->point -= $score;
        $this->save();
        PointLog::query()->create(['user_id'=>$this->id,
            'name'=>$this->name,
            'phone'=>$this->phone,
            'passport'=>$this->passport,
            'action'=>'divi',
            'point'=>$score,
            'reason'=>$reason]);
    }
}
